import sys
class Solution(object):
    def findShortestSubArray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """

        left,right,count = {},{},{}
        for index,value in enumerate(nums):
            if value not in left:
                left[value] = index
            right[value]=index
            count[value] =count.get(value,0)+1
        s = sys.maxsize
        degree = max(count.values())
        for j in count:
            if count[j] == degree:
                s = min(s,right[j]-left[j]+1)
        return s





a= [1,2,2,3,1]
s= Solution()
m =s.findShortestSubArray(a)
print(m)



